package com.foreknow.demo5;

/**
 * 计算1+.....n的偶数和
 * 用方法实现
 */
public class MethodDemo5 {
    public static int sum(int n) {
        int sum = 0;
        for(int i = 1;i<=n;i++) {
            if(i % 2 == 0){
                sum+=i;
            }
        }
//        System.out.println(sum);
        return sum;
    }

    public static int min(int[] array) {
//        int[] array = {23,1,4,34,56,78,3,12};
        int min = array[0];
        for(int i = 1;i<array.length;i++) {
            if(array[i] < min) {
                min = array[i];
            }
        }
//        System.out.println(min);
        return min;
    }

    public static void main(String[] args) {
//        int sum =  MethodDemo5.sum(100);
//        System.out.println(sum);
        int[] arr = {23,1,4,34,56,78,3,12};
        int num = MethodDemo5.min(arr);
        System.out.println(num);



    }
}
